package com.ruoyi.project.newhope.setting.controller;

import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.project.newhope.setting.domain.NewHopeSetting;
import com.ruoyi.project.newhope.setting.service.INewHopeSettingService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 全局设置Controller
 * 
 * @author ruoyi
 * @date 2021-02-08
 */
@Controller
@RequestMapping("/api/newhope/setting")
public class NewHopeSettingController extends BaseController
{

    @Autowired
    private INewHopeSettingService newHopeSettingService;

    /**
     * 查询全局设置列表
     */
    @GetMapping("/list")
    @ResponseBody
    public TableDataInfo list(NewHopeSetting newHopeSetting)
    {
        startPage();
        List<NewHopeSetting> list = newHopeSettingService.selectNewHopeSettingList(newHopeSetting);
        return getDataTable(list);
    }

    /**
     * 新增保存全局设置
     */
    @Log(title = "全局设置", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(@RequestBody NewHopeSetting newHopeSetting)
    {
        return toAjax(newHopeSettingService.insertNewHopeSetting(newHopeSetting));
    }

    /**
     * 修改全局设置
     */
    @GetMapping("/edit/{id}")
    @ResponseBody
    public AjaxResult edit(@PathVariable("id") Long id)
    {
        NewHopeSetting newHopeSetting = newHopeSettingService.selectNewHopeSettingById(id);
        return AjaxResult.success(newHopeSetting);
    }

    /**
     * 修改保存全局设置
     */
    @Log(title = "全局设置", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(@RequestBody NewHopeSetting newHopeSetting)
    {
        return toAjax(newHopeSettingService.updateNewHopeSetting(newHopeSetting));
    }

    /**
     * 删除全局设置
     */
    @Log(title = "全局设置", businessType = BusinessType.DELETE)
    @GetMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String id)
    {
        return toAjax(newHopeSettingService.deleteNewHopeSettingByIds(id));
    }
}
